<template>
    <div>
        <!-- <div class="form-login">
          <h3>用户登陆</h3>
          <ul>
              <li class="inp-box">
                  <span class="lg1"></span>
                  <span>用户名</span>
                  <input type="text" name="userInp" id="userInp"  />
              </li>
              <li class="inp-box">
                  <span class="lg2"></span>

                  <input type="password" name="passInp" id="passInp"  />
              </li>
              <li class="inp-code">
                  <span class="lg3"></span>
                  <input type="text" name="codeInp" id="codeInp" value="" />
                  <img ref="codeImg"  @click='changeCode' alt="验证" width="150px" height="45px" class="fr" style='cursor:pointer'/>
              </li>
              <li>
                  <input type="button" @click="loginClick" value="登陆" class="loginbtn" />
              </li>
          </ul>
        </div> -->
        <div class="form-login" >
          <h3>用户登录</h3>
          <el-form label-width="60px" label-position="right" size="mini">
            <el-form-item label="用户名" prop="userName">
              <el-input v-model="form.userName"></el-input>
            </el-form-item>
            <el-form-item label="密码" prop="passWord">
              <el-input type="password" v-model="form.passWord"></el-input>
            </el-form-item> 
            <el-form-item label="验证码" prop="code">
              <el-row>
                <el-col :span="11">
                  <el-input  v-model="form.code" size="medium"></el-input>
                </el-col>
                <el-col :span="2"></el-col>
                  <img ref="codeImg"  @click='changeCode' alt="验证" width="100px" height="35px" class="fr" style='cursor:pointer;margin-right:25px;'/>
                <el-col :span="11">
                </el-col>
              </el-row>    
            </el-form-item>

            <el-button 
            type="primary" 
            style="width:100%" 
            v-loading="load"
            @click="loginClick"
            >
            登录
            </el-button>

          </el-form>
        </div>
    </div>
</template>

<script>
import $ from "jquery";
import md5 from "js-md5";
export default {
  name: "LoginForm",
  data() {
    return {
      form: {
        userName: "",
        passWord: "",
        code: ""
      },
      load: false
    };
  },
  methods: {
    changeCode() {
      this.$refs.codeImg.src =
        "/api/admin/captcha-image.jpg?" + new Date().getTime();
    },
    loginClick() {
      //验证
      let _this = this; 
      if (_this.form.userName == "") {
        this.$alert("用户名不能为空", "提示信息", {
          confirmButtonText: "确定"
        });
      } else if (_this.form.passWord == "") {
        this.$alert("密码不能为空", "提示信息", {
          confirmButtonText: "确定"
        });
      } else if (_this.form.code == "") {
        this.$alert("验证码不能为空", "提示信息", {
          confirmButtonText: "确定"
        });
      } else {
        
        _this.load = true
        // _this.$router.push({ path: "/home/index" });
        $.ajax({
          type: "POST",
          url: "/api/admin/login/byaccount",
          async: true,
          data: {
            acc: _this.form.userName,
            pwd: md5(_this.form.passWord),
            verifyCode: _this.form.code
          },
          dataType: "json",
          success: function(data) {
            if (data.status == 0) {
              _this.load = false;
              _this.$router.push({ path: "/home/index" });
            } else {
              _this.$alert(data.msg, "提示信息", {
                confirmButtonText: "确定"
              });
               _this.load = false;
            }
          }
        });
      }
    }
  },
  mounted() {
    this.$refs.codeImg.src =
      "/api/admin/captcha-image.jpg?" + new Date().getTime();
  }
};
</script>

<style scoped>
.form-login {
  width: 360px;
  padding: 30px;
  margin: 180px auto;
  background-color: #fff;
  opacity: 0.8;
  padding-top: 10px;
  box-shadow: 0 0 7px 5px #eee;
  border-radius: 8px;
}

.form-login h3 {
  height: 55px;
  line-height: 55px;
  font-weight: normal;
  font-size: 20px;
  color: #333;
  text-align: center;
}

#loginBtn {
  width: 100%;
}

/* .form-login ul li {
  width: 330px;
  height: 45px;
  line-break: 45px;
  margin: 20px auto;
}

.form-login li span {
  width: 45px;
  height: 45px;
  display: inline-block;
  float: left;
  background: url(../../../assets/images/icon_lg.png) no-repeat;
} */

/* .form-login li span.lg2 {
  background-position: 0 -45px;
}

.form-login li span.lg3 {
  background-position: 0 -90px;
} */

/* .form-login li.inp-box input {
  width: 285px;
  height: 45px;
  border: none;
  background-color: #eee;
}

.form-login li.inp-code input {
  width: 120px;
  height: 45px;
  border: none;
  background-color: #eee;
  color: #aaa;
}

.form-login .loginbtn {
  width: 330px;
  height: 45px;
  background-color: dodgerblue;
  opacity: 0.5;
  color: #333;
  text-align: center;
  font-size: 16px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
} */
</style>
